<?php
class M_TourCategory extends Apps_Db_Table_Abstract {
    protected $_name = 'tour_category';

    public function listCategoryShowHome() {
        $q = $this->_db
                  ->select()
                  ->from('tour_category', null)
                  ->where('tour_category.show_home =? ', 1)
                  ->order('tour_category.sorting_number ASC')
                  ->limit('2')
                  ->columns(array('id' => 'tour_category.id'));

        if($this->getLang() == 'en') {
            $q->columns(array('tour_category_title' => 'tour_category.en_title'));
        } else $q->columns(array('tour_category_title' => 'tour_category.title'));

        return $q;
    }

    //list tour category by countryId
    public function listTourCategoryByCountryId($countryId) {
        $q = $this->_db
                  ->select()
                  ->from('tour_category', null)
                  ->join('tour', 'tour.tour_category_id = tour_category.id', null)
                  ->join('country', 'country.id = tour.country_id', null)
                  ->where('tour_category.status =? ', 1)
                  ->where('tour.status =? ', 1)
                  ->where('country.id =? ', $countryId)
                  ->group('tour_category.id')
                  ->columns(array('id' => 'tour_category.id'));

        if($this->getLang() == 'en') {
            $q->columns(array('tour_category_title' => 'tour_category.en_title'));
        } else $q->columns(array('tour_category_title' => 'tour_category.title'));

        return $q;
    }

    //get tour category by id
    public function getTourCategoryById($id) {
        $q = $this->_db
                  ->select()
                  ->from('tour_category', null)
                  ->where('tour_category.status =? ', 1)
                  ->where('tour_category.id =? ', $id)
                  ->columns(array(
                  		'id' 				  => 'tour_category.id',
                        'meta_keyword'        => 'tour_category.meta_keyword',
                        'meta_description'    => 'tour_category.meta_description',
                        'header_title'        => 'tour_category.header_title'
                  		));

        if($this->getLang() == 'en') {
            $q->columns(array('tour_category_title' => 'tour_category.en_title'));
        } else $q->columns(array('tour_category_title' => 'tour_category.title'));

        return $q;
    }
}